package com.test.vertx.job;

import io.vertx.core.eventbus.EventBus;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @ClassName Job
 * @Author wzb
 * @Date 2021/5/27 11:10
 * @Description
 */
public class Job {
    public static void main(String[] args) throws Exception {
        //得到默认的调度器
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(MyJob.class)
                .withIdentity("job", "group")
                .build();
        //传参
        job.getJobDataMap().put("eventbus", "eventBus");

        //触发器
        Trigger trigger = newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/10 * * * * ?"))
                .build();
        //注册作业和触发器
        if (!scheduler.checkExists(job.getKey())) {
            scheduler.scheduleJob(job, trigger);
        }
        //开始调度任务
        scheduler.start();
    }
}

